package main

import (
	"log"
	"os"
	"path"
	"time"
)

func PrepareLog() (logFile *os.File) {
	var err error
	logDir := path.Join(*basepath, "log")
	if err := os.MkdirAll(logDir, 0755); err != nil {
		log.Panic(err)
		logDir = *basepath
	}
	date := time.Now().Format("2006-01-02")
    filename := "crmpost." + date + ".log"
	logpath := path.Join(logDir, filename)
	logfile, err := os.OpenFile(logpath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
	if err != nil {
		log.Panic(err)
	}
	log.SetOutput(logfile)
	return logfile
}
/*
func SwitchLogFile(file *os.File) {
	mu := sync.RWMutex{}
	mu.Lock()
	PrepareLog()
	file.Close()
	mu.Unlock()
}
*/
